/**
 * Created by sun on 2016/8/4.
 */
define(function(require) {
	var app = require('/../js/app');
	require('ui-table');


	var toastr =require('toastr');
	app.useModule("ui.table");


	var datepicker = require('datepicker');
	app.controller('guarantee_cashCtrl', ['$scope', '$http','$filter',
		function($scope, $http,$filter) {
			$scope.ctrlScope=$scope;
			$scope.orderParams = {
				url: "/admin/accountcash/listByGuaranteeId"
			};
			datepicker($scope);

			//创建
			$scope.addOrderModal = function() {
				$scope.orderModal = !$scope.orderModal;
			};

			//全局查询
			$scope.search = function() {
				$scope.ctrlScope.itemsearch.beginDateTime=$scope.ctrlScope.itemsearch.beginDateTimex;
				$scope.ctrlScope.itemsearch.endDateTime=$scope.ctrlScope.itemsearch.endDateTimex;
				$scope.ctrlScope.itemsearch.beginDateTime=$filter('date')($scope.ctrlScope.itemsearch.beginDateTime,'yyyy-MM-dd');
				$scope.ctrlScope.itemsearch.endDateTime=$filter('date')($scope.ctrlScope.itemsearch.endDateTime,'yyyy-MM-dd');
				//表格查询参数设置
				$scope.orderParams.ajaxParam=$scope.ctrlScope.itemsearch;

				var parm =$scope.ctrlScope.itemsearch;
				$scope.getShow(parm);
				//表格刷新
				$scope.orderParams.reload();
			};

			//全局查询重置
			$scope.reset=function(){
				$scope.ctrlScope.itemsearch={};
				$scope.orderParams.ajaxParam={};
				$scope.orderParams.reload();
				$scope.getShow();
			};

			//新建
			$scope.addOrderModal=function(){
				$scope.add={};
				$http({
					method: 'POST',
					url: "/admin/account/getByUserId",
					data:{},
				}).success(function(data) {
					$scope.addModal=!$scope.addModal;
					console.info(data);
					$scope.add.cash=data.cash;

				}).error(function(data) {
				});
			};

			//新建
			$scope.adoptAdd=function(){
				var param=$scope.add;
				$http({
					method: 'POST',
					url: "/admin/accountcash/cash",
					data:param,
				}).success(function(data) {
					if(data.result=="fail"){
						console.info(data);
						toastr.error(data.messageText);
					}else{
						toastr.success("提现成功");
						$scope.addModal=! $scope.addModal;
						$scope.orderParams.reload();
					}
				}).error(function(data) {
				});
			};
		}
	]);


});